package com.xiaoqian.partyembassy.ui.activity;

import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ListView;

import com.alibaba.fastjson.JSONObject;
import com.xiaoqian.partyembassy.R;
import com.xiaoqian.partyembassy.adapter.SearchExhibitsAdpter;
import com.xiaoqian.partyembassy.adapter.SearchHistoryAdpter;
import com.xiaoqian.partyembassy.base.BaseActivity;
import com.xiaoqian.partyembassy.constant.UrlConfig;
import com.xiaoqian.partyembassy.tools.CommonToolUtils;
import com.xiaoqian.partyembassy.tools.okhttp.CallBackUtil;
import com.xiaoqian.partyembassy.tools.okhttp.OkhttpUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.Call;

/**
 * @项目名称:
 * 包: com.dnake.yunduijiang
 * 类名称:搜索
 * @类描述:
 * @创建人: 黄飞
 * @创建时间:
 * @修改人:
 * @修改时间:
 * @修改备注:
 * @版本: v1.0
 */

public class SearchActivity extends BaseActivity implements AdapterView.OnItemClickListener {
    private GridView all_exhibits_history_gv;
    private ListView all_exhibits_history_lv;
    private View search_empty_view;
    private EditText search_edt;
    @Override
    protected int getLayoutId() {
        return R.layout.activity_search;
    }

    @Override
    protected void initParams() {

    }

    @Override
    protected void initView() {
        all_exhibits_history_gv = findViewById(R.id.all_exhibits_history_gv);
        search_edt = findViewById(R.id.search_edt);
        List<String> mList = new ArrayList<>();
        mList.add("");
        mList.add("");
        mList.add("");
        SearchHistoryAdpter searchHistoryAdpter = new SearchHistoryAdpter(mContext,mList);
        all_exhibits_history_gv.setAdapter(searchHistoryAdpter);
        all_exhibits_history_gv.setOnItemClickListener(this);
       all_exhibits_history_lv = findViewById(R.id.all_exhibits_history_lv);
        SearchExhibitsAdpter searchExhibitsAdpter = new SearchExhibitsAdpter(mContext,mList);
        search_empty_view = findViewById(R.id.search_empty_view);
        search_edt.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (s.length() == 0) {

                } else {
                    searchData((String) s);
                }
            }
            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }
    private void searchData(String text){
        Map<String,String> paramsMap = new HashMap<>();
        paramsMap.put("indoor-uid","0");
        paramsMap.put("indoor-token","1234567890123456");
        paramsMap.put("text ",text);
        OkhttpUtil.okHttpPost(UrlConfig.getExhibitsByText, paramsMap, new CallBackUtil.CallBackString() {
            @Override
            public void onFailure(Call call, Exception e) {
                Log.e("onFailure",e.toString()+"-");
            }
            @Override
            public void onResponse(String response) {
                Log.e("onFailure",response+"-");
                JSONObject json = CommonToolUtils.getJSON(response);
                if(null != json){

                }
            }
        });
    }
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        switch (parent.getId()) {
            case R.id.all_exhibits_history_gv://历史
            case R.id.all_exhibits_history_lv://
                startActivity(VenueProfilesActivity.class);
                break;
        }

    }
}
